package com.foxzzz.temporary;

public class Solution1041 {
    public boolean isRobotBounded(String instructions) {
       int top=0,right=0,right_add=0;
        int top_add=1;

            for (int j = 0; j < instructions.length(); j++) {
                char c = instructions.charAt(j);
                if (c != 'G') {
                    int flag = 1;
                    if (c == 'R')
                        flag = -1;
                    if (top_add != 0) {
                        right_add = -top_add * flag;
                        top_add = 0;

                    } else {
                        top_add = right_add * flag;
                        right_add = 0;
                    }
                } else {
                    top += top_add;
                    right += right_add;
                }

            }
        //原地
        if (top == 0 && right == 0)
                return true;
        //2次能回的
        if(top_add<0&&right==0)
               return  true;
        //4次能回的
        if(right==0)
                return  true;
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1041().isRobotBounded("GL"));
    }

}
